<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">

    <h:head>
        <title>Planos de Conta</title>
    </h:head>

    <ui:composition template="/index.xhtml">
        <ui:define name="conteudo">
            <f:view>
                <h:body>
                    <h:form id="formPlanosDeConta" >

                        <p:growl autoUpdate="true" showDetail="true"/>

                        <p:panel header="Planos de Conta">

                            <p:dataTable id="dtPlanosDeConta"
                                         var="item"
                                         value="#{planoDeContaBean.planosDeConta}"
                                         selectionMode="single"
                                         selection="#{planoDeContaBean.planoDeConta}"
                                         rowKey="#{item.id}"
                                         emptyMessage="N&atilde;o h&aacute; dados">

                                <p:column headerText="Código"
                                          style="width: 15px; text-align: center" 
                                          filterBy="#{item.codigo}" 
                                          filterMatchMode="contains" >

                                    <h:outputText value="#{item.codigo}" />

                                </p:column>

                                <p:column headerText="Descrição" 
                                          style="width: 35%"
                                          filterBy="#{item.descricao}" 
                                          filterMatchMode="contains"
                                          filterStyle="width: 90%">

                                    <h:outputText value="#{item.descricao}" />

                                </p:column>

                                <p:column headerText="Tipo de Conta" 
                                          style="width: 20%; text-align: center">

                                    <h:outputText value="DÉBITO"
                                                  rendered="#{item.tipoConta  eq 'D'}"/>

                                    <h:outputText value="CRÉDITO"
                                                  rendered="#{item.tipoConta  eq 'C'}"/>

                                </p:column>

                                <p:column headerText="Saldo Inicial" 
                                          style="width: 20%">
                                    <h:outputText value="#{item.saldoInicial}" >
                                        <f:convertNumber currencyCode="R$" />
                                    </h:outputText>
                                </p:column>

                            </p:dataTable>

                            <br/>

                            <!-- Botões para o CRUD -->

                            <p:commandButton value="Novo"
                                             actionListener="#{planoDeContaBean.adicionarInicio}"
                                             oncomplete="dlgPlanoDeConta.show()"
                                             update=":display"/>

                            <p:commandButton value="Editar"
                                             actionListener="#{planoDeContaBean.editarInicio}"
                                             update=":display"/>

                            <p:commandButton value="Excluir"
                                             actionListener="#{planoDeContaBean.excluirInicio}"/>

                        </p:panel>
                    </h:form>

                    <!-- confirmDialog para confirmação de exclusão -->

                    <p:confirmDialog  message="Deseja excluir esse registro?"
                                      severity="alert"
                                      header="Exclus&atilde;o"
                                      widgetVar="dlgExcluirPlanoDeConta"
                                      appendToBody="true">

                        <h:form>

                            <p:commandButton id="confirm"
                                             value="Sim"
                                             actionListener="#{planoDeContaBean.excluirFim}"
                                             update=":formPlanosDeConta:dtPlanosDeConta"/>

                            <p:commandButton id="decline"
                                             value="N&atilde;o"
                                             onclick="dlgExcluirPlanoDeConta.hide();"
                                             actionListener="#{planoDeContaBean.cancelar}"
                                             update=":formPlanosDeConta:dtPlanosDeConta" />

                        </h:form>

                    </p:confirmDialog>

                    <p:dialog header="Plano de Conta" 
                              widgetVar="dlgPlanoDeConta"
                              appendToBody="true"
                              showEffect="clip"
                              hideEffect="clip"
                              dynamic="true"
                              modal="true"
                              resizable="false" >

                        <h:panelGrid id="display"
                                     style="width: 400px">

                            <ui:include src="PlanoDeConta.xhtml" />

                        </h:panelGrid>

                    </p:dialog>
                </h:body>
            </f:view>
        </ui:define>
    </ui:composition>

</html>

